<?php
use App\Winged\Auth\Consts\Permissions;
use \Illuminate\Support\Facades\Route;
use \Illuminate\Routing\Router;

$attrbutes               = [
    'prefix'    => \Encore\Admin\Facades\Admin::url($this->modulePrefix),
    'namespace' => 'App\Winged\\' . $this->moduleName . '\Controllers',
];
$prefix                  = 'permission:allow,';
$middleware              = [
    'system' => ['web', 'admin', $prefix . \App\Winged\Auth\Consts\Roles::MASTER_SUPERADMIN]
];
$attrbutes['middleware'] = $middleware ['system'];
/* 浏览权限 */
Route::group($attrbutes, function (Router $router) {
    $router->get('/roles', 'AuthController@roles');
    $router->get('/roles', 'AuthController@roles');
    // 在admin目录下面的我文件
    $router->resource('/logs', '\App\Admin\Controllers\LogController', ['only' => ['index', 'destroy']]);
});

/**   用户管理权限  ***/
$prefix                  = 'permission:allow,';
$middleware              = [
    'system' => ['web', 'admin', $prefix . \App\Winged\Auth\Consts\Roles::MASTER_SUPERADMIN . ',' . \App\Winged\Auth\Consts\Roles::TENANT_ADMIN]
];
$attrbutes['middleware'] = $middleware ['system'];
/* 浏览权限 */
Route::group($attrbutes, function (Router $router) {
    $router->get('/users', 'AuthController@users');
    $router->post('/users', 'AuthController@users');
    $router->put('/users', 'AuthController@edit');
    $router->post('/adduser', 'AuthController@addUser');
    $router->post('/info', 'AuthController@info');
});

/// 帮助
$attrbutes ['prefix'] = \Encore\Admin\Facades\Admin::url('/helpers');
Route::group($attrbutes, function (Router $router) {
    $router->get('terminal/artisan', '\App\Admin\Controllers\TerminalController@artisan');
    $router->post('terminal/artisan', '\App\Admin\Controllers\TerminalController@runArtisan');
    // 以下2个暂时没啥用
    $router->get('scaffold', '\App\Admin\Controllers\ScaffoldController@index');
    $router->post('scaffold', '\App\Admin\Controllers\ScaffoldController@store');
    // 操作数据库，慎用
    $router->get('terminal/database', '\App\Admin\Controllers\TerminalController@database');
    $router->post('terminal/database', '\App\Admin\Controllers\TerminalController@runDatabase');
});

// 修改密码
$attr = [
    'middleware' => ['web', 'admin'],
    'namespace'  => '\App\Winged\\Auth\\Controllers',
    'prefix'     => config('admin.prefix'),
];
Route::group($attr, function (\Illuminate\Routing\Router $router) {
    $router->get('auth/reset', 'AuthController@reset');
    $router->post('auth/reset', 'AuthController@resetPost');
});


$attr = [
    'middleware' => ['web', 'tenants'],
    'namespace'  => '\App\Winged\\Auth\\Controllers',
    'prefix'     => config('admin.prefix'),
];
Route::group($attr, function (\Illuminate\Routing\Router $router) {
    $router->get('auth/login', 'AuthController@getLogin');
    $router->post('auth/login', 'AuthController@postLogin');
    $router->get('auth/logout', 'AuthController@getLogout');
});
